package com.java.escape.computeAndListOrInterface;


import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
 * @ClassName IteratorList
 * @Description Iterator 使用的常见错误
 * @Author wyp
 * @Date 2023/8/23 15:31
 * @Version 1.0
 */
public class IteratorList {

    public static void main(String[] args) {
        List<Integer> integers = List.of(1, 2, 3, 4, 7, 5);
        List<Integer> integers1 = List.of(5, 6, 7, 8);
        //增加for循环
//        for (Integer integer : integers1) {
//            for (Integer integer1 : integers1) {
//                System.out.println(integer * integer1);
//            }
//        }
        //NoSuchElementException
        //迭代器嵌套循环
//        for (Iterator<Integer> iterator = integers.iterator(); iterator.hasNext(); ) {
//            for (Iterator<Integer> iterator1 = integers1.iterator(); iterator1.hasNext(); ) {
//                System.out.println(iterator.next() * iterator1.next());
//            }
//
//        }
        //迭代器嵌套的正确使用
        for (Iterator<Integer> iterator = integers.iterator(); iterator.hasNext(); ) {
            Integer temp = iterator.next();
            for (Iterator<Integer> iterator1 = integers1.iterator(); iterator1.hasNext(); ) {
                System.out.println(temp * iterator1.next());
            }

        }
        System.out.println(integers.size());
    }

}
